# coding: utf8
import psutil


def get_netcard():
    """
    获取网卡名称和其ip地址，不包括回环
    :return: list [(network_card, ip), ]
    """
    netcard_info = []
    info = psutil.net_if_addrs()
    for k, v in info.items():
        for item in v:
            if item[0] == 2 and not item[1]=='127.0.0.1':
                print(k, '---', '*0*', item[0], '0000', item[1])
                netcard_info.append((k, item[1]))
    return netcard_info


def get_ip():
    """
    获取网卡名称和其ip地址，不包括回环
    :return: dict {network_card: ip}
    """
    netCard_info = {}
    info = psutil.net_if_addrs()
    for k, v in info.items():  # 遍历所有网卡 - 包括 虚拟网卡；
        for item in v:  # 遍历网卡内信息；
            if item[0] == 2 and (not item[1] == '127.0.0.1'):  # 判断内容
                print(k, '---', '*0*', item[0], '*1*', item[1])
                netCard_info[k] = item[1]
    return netCard_info


if __name__ == '__main__':
    print(get_ip())
